import requests
from sympy.physics.vector.printing import params

corpid="ww778f816255b60fb1"
corpsecret="VR1ip1Zye1_9FQ4xDHQxIMZuMR5QgYsfUCSsO7MhJGM"

appsecret="6vLlctDTuGl1vpG92KOAm6B-E9RwNAxDXb3VxDvpAJw"



def gettoken():
    gettoken_url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken"

    parmas = {"corpid":corpid,"corpsecret":appsecret}

    try:
        response = requests.get(gettoken_url,params)
        if response.ok:
            result = response.json()
            if result["errcode"] == 0:
                access_token = result["access_token"]
                return access_token
            print(f"获取token failed ...return data is:{result}")
        return ""

    except requests.exceptions.HTTPError as e:
        print(f"Http... error...｛e｝")
    except requests.exceptions.ConnectionError as e:
        print(f"...Connection  error...｛e｝")
    except requests.exceptions.RequestException as e:
        print(f".. other error...{e}")
    except Exception as e:
        print(f"app error:{e}")


def getdepts():
    token = gettoken()
    dept_url = "https://qyapi.weixin.qq.com/cgi-bin/department/list"



if __name__ == '__main__':
    token = gettoken()
    print(token)

